const nodeList = {
  task: () => {
    console.log('root')
  },
  child: {
    task: () => {
      console.log('root child')
    },
    child: {
      task: () => {
        console.log('root child child')
      },
    },
  },
}
// 01.链表的基本遍历
const runNode = (node)=>{
    node.task()
    if(node.child){
        runNode(node.child)
    }
}
// runNode(nodeList)

// 02.链表的requestIdleCallback遍历
const useIdelNodeList = (node) => {
  const callBack = (IdleDeadline) => {
    const getTimeOut = () => IdleDeadline.timeRemaining()
    const hasTime = () => getTimeOut() > 1
    console.log('callBack', getTimeOut())
    while (hasTime() && node) {
      node.task()
      node = node.child
    }
    node && requestIdleCallback(callBack)
  }
  requestIdleCallback(callBack)
}
// useIdelNodeList(nodeList)
